package com.omazan.srvlts;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.omazan.facace.CustomerActions;
import com.omazan.facace.models.RegisterDetails;
import com.omazan.utils.OmazanException;

/**
 * Servlet implementation class RegisterUser
 */
@WebServlet("/RegisterUser")
public class RegisterUser extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public RegisterUser() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {



	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		

		RegisterDetails details = new RegisterDetails();
		details.userName = request.getParameter("userName");
		details.userPassword = request.getParameter("userPwd");
		details.repeatPassword = request.getParameter("repuserPwd");
		details.firstName = request.getParameter("firstName");
		details.lastName = request.getParameter("lastName");
		details.houseNo = request.getParameter("houseNo");
		details.street = request.getParameter("street");
		details.city = request.getParameter("city");
		details.state = request.getParameter("state");
		details.country = request.getParameter("country");
		details.mobileNo = request.getParameter("mobileNo");
		details.email = request.getParameter("email");
		
		details.userType = request.getParameter("usertype");
		boolean regSuccess = false;
		try {
			regSuccess = new CustomerActions().registerCustomer(details);
		} catch (OmazanException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			request.getSession().setAttribute("message", "Registration failed");
			response.sendRedirect("index.jsp");
		}
		
		if(regSuccess){
			request.getSession().setAttribute("message", "Registration failed");
			response.sendRedirect("index.jsp");
		}
		
		

	}

}
